home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / inetutil.1 / inetutil / inetutils-1.1 / talk / init_disp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-22  |  5.1 KB  |  192 lines

  1. /*
  2.  * Copyright (c) 1983, 1993
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #ifndef lint
  35. static char sccsid[] = "@(#)init_disp.c    8.2 (Berkeley) 2/16/94";
  36. #endif /* not lint */
  37.  
  38. /*
  39.  * Initialization code for the display package,
  40.  * as well as the signal handling routines.
  41.  */
  42.  
  43. #ifdef HAVE_CONFIG_H
  44. #include <config.h>
  45. #endif
  46.  
  47. #ifdef HAVE_TERMIOS_H
  48. #include <termios.h>
  49. #else
  50. #include <sys/ioctl.h>
  51. #ifdef HAVE_SYS_IOCTL_COMPAT_H
  52. #include <sys/ioctl_compat.h>
  53. #endif
  54. #endif
  55.  
  56. #include <signal.h>
  57. #include <err.h>
  58. #include "talk.h"
  59.  
  60. /* 
  61.  * Set up curses, catch the appropriate signals,
  62.  * and build the various windows.
  63.  */
  64. init_display()
  65. {
  66.     void sig_sent();
  67.     struct sigvec sigv;
  68.  
  69.     if (initscr() == NULL)
  70.         errx(1, "Terminal type unset or lacking necessary features.");
  71.     (void) sigvec(SIGTSTP, (struct sigvec *)0, &sigv);
  72.     sigv.sv_mask |= sigmask(SIGALRM);
  73.     (void) sigvec(SIGTSTP, &sigv, (struct sigvec *)0);
  74.     curses_initialized = 1;
  75.     clear();
  76.     refresh();
  77.     noecho();
  78.     crmode();
  79.     signal(SIGINT, sig_sent);
  80.     signal(SIGPIPE, sig_sent);
  81.     /* curses takes care of ^Z */
  82.     my_win.x_nlines = LINES / 2;
  83.     my_win.x_ncols = COLS;
  84.     my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0);
  85.     scrollok(my_win.x_win, FALSE);
  86.     wclear(my_win.x_win);
  87.  
  88.     his_win.x_nlines = LINES / 2 - 1;
  89.     his_win.x_ncols = COLS;
  90.     his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols,
  91.         my_win.x_nlines+1, 0);
  92.     scrollok(his_win.x_win, FALSE);
  93.     wclear(his_win.x_win);
  94.  
  95.     line_win = newwin(1, COLS, my_win.x_nlines, 0);
  96.     box(line_win, '-', '-');
  97.     wrefresh(line_win);
  98.     /* let them know we are working on it */
  99.     current_state = "No connection yet";
  100. }
  101.  
  102. /*
  103.  * Trade edit characters with the other talk. By agreement
  104.  * the first three characters each talk transmits after
  105.  * connection are the three edit characters.
  106.  */
  107. set_edit_chars()
  108. {
  109.     int cc;
  110.     char buf[3];
  111.  
  112. #ifdef HAVE_TCGETATTR
  113.       struct termios tty;
  114.     cc_t disable = (cc_t)-1, erase, werase, kill;
  115.  
  116. #if !defined (_POSIX_VDISABLE) && defined (HAVE_FPATHCONF) && defined (_PC_VDISABLE)
  117.     disable = fpathconf (0, _PC_VDISABLE);
  118. #endif
  119.  
  120.     erase = werase = kill = disable;
  121.  
  122.     if (tcgetattr (0, &tty) >= 0) {
  123.         erase = tty.c_cc[VERASE];
  124. #ifdef VWERASE
  125.         werase = tty.c_cc[VWERASE];
  126. #endif
  127.         kill = tty.c_cc[VKILL];
  128.     }
  129.  
  130.     if (erase == disable)
  131.         erase = '\177';    /* rubout */
  132.     if (werase == disable)
  133.         werase = '\027'; /* ^W */
  134.     if (kill == disable)
  135.         kill = '\025';    /* ^U */
  136.  
  137.     my_win.cerase = erase;
  138.     my_win.werase = werase;
  139.     my_win.kill = kill;
  140. #else /* !HAVE_TCGETATTR */
  141.     struct sgttyb tty;
  142.     struct ltchars ltc;
  143.     
  144.     ioctl(0, TIOCGETP, &tty);
  145.     ioctl(0, TIOCGLTC, (struct sgttyb *)<c);
  146.     my_win.cerase = tty.sg_erase;
  147.     my_win.kill = tty.sg_kill;
  148.     if (ltc.t_werasc == (char) -1)
  149.         my_win.werase = '\027';     /* control W */
  150.     else
  151.         my_win.werase = ltc.t_werasc;
  152. #endif /* HAVE_TCGETATTR */
  153.  
  154.     buf[0] = my_win.cerase;
  155.     buf[1] = my_win.kill;
  156.     buf[2] = my_win.werase;
  157.     cc = write(sockt, buf, sizeof(buf));
  158.     if (cc != sizeof(buf) )
  159.         p_error("Lost the connection");
  160.     cc = read(sockt, buf, sizeof(buf));
  161.     if (cc != sizeof(buf) )
  162.         p_error("Lost the connection");
  163.     his_win.cerase = buf[0];
  164.     his_win.kill = buf[1];
  165.     his_win.werase = buf[2];
  166. }
  167.  
  168. void
  169. sig_sent()
  170. {
  171.  
  172.     message("Connection closing. Exiting");
  173.     quit();
  174. }
  175.  
  176. /*
  177.  * All done talking...hang up the phone and reset terminal thingy's
  178.  */
  179. quit()
  180. {
  181.  
  182.     if (curses_initialized) {
  183.         wmove(his_win.x_win, his_win.x_nlines-1, 0);
  184.         wclrtoeol(his_win.x_win);
  185.         wrefresh(his_win.x_win);
  186.         endwin();
  187.     }
  188.     if (invitation_waiting)
  189.         send_delete();
  190.     exit(0);
  191. }
  192.